<template>
  <nav :style="{ position: fixed ? 'fixed' : 'static' }">
    <ul>
      <li>
        <router-link to="/movie/thehit" active-class="active">
          <span>正在热映</span>
        </router-link>
      </li>
      <li>
        <router-link to="/movie/terelease" active-class="active">
          <span>即将上映</span>
        </router-link>
      </li>
    </ul>
  </nav>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";

let fixed = ref<boolean>(false);

onMounted(() => {
  window.addEventListener("scroll", () => {
    let top = document.documentElement.scrollTop;
    if (top > 100) {
      fixed.value = true;
    } else {
      fixed.value = false;
    }
  });
});
</script>

<style lang="scss" scoped>
nav {
  width: 100%;
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #eaeaea;
  top: 0;
  left: 0;
  background-color: #fff;

  ul {
    display: flex;
    text-align: center;

    li {
      flex: 1;
      display: flex;
      justify-content: center;
      a.active {
        width: 40%;
        border-bottom: 2px solid red;
        display: block;
        color: #fe5100;
      }
    }
  }
}
a {
  color: #000;
}
</style>
